<template>
  <div>
    <div class="maincss">
      <el-row>
        <el-card>
<!--          <searchBox title='知识库' :btn='btn' @func='showBtn'/>-->
          <el-row class="searchbox">
            <el-col span="1"> 知识库 </el-col>
            <el-col span="3">
              <el-input
                placeholder="文件编号"
                v-model="queryParams.fileNo"
              >
              </el-input>
            </el-col>
            <el-col span="3">
              <el-input
                placeholder="文件名称"
                v-model="queryParams.fileName"
              >
              </el-input>
            </el-col>
            <el-col span="1">
              <el-button @click="handleLoadAndQuery" type="primary">查询</el-button>
            </el-col>
            <el-col span="2">
              <el-button @click="handleOpenAdd" type="primary">新增</el-button>
            </el-col>
          </el-row>
          <el-card class="gray-card no-border no-margin-top" shadow="never">
            <el-table
              v-loading="loading"
              :data="checkList"
              style="width: 100%;"
            >
              <el-table-column label="文件编号" align="center" prop="fileNo" :show-overflow-tooltip="true"/>
              <el-table-column label="文件名称" align="center" prop="fileName" :show-overflow-tooltip="true"/>
              <el-table-column label="最新版本号" align="center" prop="checkName"/>
              <el-table-column label="文件类型" align="center" prop="fileType" :show-overflow-tooltip="true"/>
              <el-table-column label="所属项目" align="center" prop="projectName" :show-overflow-tooltip="true"/>
              <el-table-column label="来源科室" align="center" prop="deptName"/>
              <el-table-column label="创建者" align="center" prop="creater"/>
              <el-table-column label="发布时间" align="center" prop="publishTime"/>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleOpenEdit(scope.row)"
                  >编辑
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleOpenDetail(scope.row)"
                  >详情
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>

          <pagination v-show="total>0" :total="total"
                      :page.sync="queryParams.pageNum"
                      :limit.sync="queryParams.pageSize"
                      @pagination="handleLoadAndQuery"/>

        </el-card>
      </el-row>
    </div>
    <el-drawer
      :title="title"
      :visible.sync="isVisibleAdd"
      size='65%'
    >
      <addKnowledge
        @close='handleCloseAdd'
        :disabled="disabled"
        ref="AddRef"/>
    </el-drawer>
  </div>
</template>

<script>

import addKnowledge from "@/views/examSys/components/addKnowledge"
import {ListPage, getKnowledge} from "@/api/business/knowledge"

export default {
  name: "maintenanceInfo",
  components: {
    addKnowledge
  },
  data() {
    return {
      btn: {
        add: true,
        reg: false,
        down: false,
        export: true,
        imp: false,
        search: true
      },
      checkList: [],
      loading: false,
      redirect: undefined,
      activeName: '1',
      value: '',
      total: 5,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        fileName: '',
        fileNo: ''
      },
      isVisibleAdd: false,
      title: '新增',
      disabled: false
    };
  },
  watch: {},
  created() {
    this.handleLoadAndQuery()
  },
  methods: {
    showBtn(data) {
      if (data == 'add') {
       this.handleOpenAdd()
      }
      if (data === 'search') {
        this.handleLoadAndQuery()
      }
    },
    handleOpenAdd() {
      this.isVisibleAdd = true
      this.disabled = false
      this.title = '新增'
    },
    handleOpenEdit(row) {
      this.title = '编辑'
      this.disabled = false
      this.isVisibleAdd = true
      this.$nextTick(() => {
        this.$refs.AddRef.handleData(row)
      })
    },
    handleOpenDetail(row) {
      this.title = '详情'
      this.disabled = true
      this.isVisibleAdd = true
      this.$nextTick(() => {
        this.$refs.AddRef.handleData(row)
      })
    },
    handleCloseAdd() {
      this.isVisibleAdd = false
      this.disabled = false
      this.title = '新增'
      this.handleLoadAndQuery()
    },
    handleLoadAndQuery() {
      this.checkList = []
      this.loading = true;
      ListPage(this.queryParams).then((res) => {
        this.loading = false;
        this.total = res.total;
        this.checkList = res.records;
      })
        .catch(() => {
          this.loading = false;
        })
    }
  }
};
</script>
